package com.athuiju.gateway.handler;

import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.autoconfigure.web.ResourceProperties;

import org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorWebExceptionHandler;

import org.springframework.boot.web.reactive.error.ErrorAttributes;
import org.springframework.context.ApplicationContext;

import org.springframework.web.reactive.function.server.*;

import java.util.HashMap;
import java.util.Map;

public class JsonExceptionHandler extends DefaultErrorWebExceptionHandler {
public JsonExceptionHandler(ErrorAttributes errorAttributes, ResourceProperties resourceProperties,
                            ErrorProperties errorProperties, ApplicationContext applicationContext){
    super(errorAttributes,resourceProperties,errorProperties,applicationContext);
}
//获取异常属性
    @Override
    protected Map<String,Object>getErrorAttributes(ServerRequest request,boolean includeStackTrace){
    Map<String,Object>map=new HashMap<>();
    map.put("success",false);
    map.put("code",20005);
    map.put("message","网管失败");
    map.put("data",null);
    return  map;
    }
    //指定相应处理方法为接送处理方法
    @Override
    protected RouterFunction<ServerResponse>getRoutingFunction(ErrorAttributes errorAttributes){
    return RouterFunctions.route(RequestPredicates.all(),this::renderErrorResponse);

    }
    @Override
    protected  int getHttpStatus(Map<String,Object>errorAttributes){
    return  200;
    }
}
